/*	PID Controler WITHOUT A PHD!
http://www.embedded.com/2000/0010/0010feat3.htm

*/
#include <inttypes.h>

typedef struct SPid
{
  double dState;      	// Last position input
  double dError;
  double iState;      	// Integrator state
  double iMax, iMin;  	
  // Maximum and minimum allowable integrator state
  double	iGain,    	// integral gain
        	pGain,    	// proportional gain
         	dGain;     	// derivative gain
  double	Position;
  uint8_t	VarValue;
  uint8_t	Positive;	// specifies if it is positve or negative
  double	minTime;
  double	tGain;
  double	overValue;
  uint32_t	overTime;
  double	underValue;
  uint32_t	underTime;
  uint32_t	tDiff;
} SPid;

double UpdatePID(SPid * pid, double value, uint32_t* Ticks, double error, double position);
